﻿default_created_by = 'db/seeds.rb'


###############################################################################
# USER GROUPS
###############################################################################

user_group_admins = UserGroup.create(
	name: 'Administrators',
	created_by: default_created_by
)
user_group_admins.translations.create(description: 'Group for all site administrators. Simple as that.', locale: 'en')
user_group_admins.translations.create(description: 'Gruppe für alle Seitenadministratoren.', locale: 'de')

user_group_users = UserGroup.create(
	name: 'Users',
	created_by: default_created_by
)
user_group_users.translations.create(description: 'Group for all registered and logged-in users of the website.', locale: 'en')
user_group_users.translations.create(description: 'Gruppe für alle registrierten und angemeldeten Benutzer der Webseite.', locale: 'de')

user_group_guests = UserGroup.create(
	name: 'Guests', 
	created_by: default_created_by
)
user_group_guests.translations.create(description: 'Group for all un-registered or not logged-in users of the website.', locale: 'en')
user_group_guests.translations.create(description: 'Gruppe für alle nicht-registrierten und nicht-angemeldeten Benutzer der Webseite.', locale: 'de')


###############################################################################
# PERMISSIONS
###############################################################################

# STATIC PAGES
static_pages_permission_home = Permission.create(
	key: 'StaticPages.home',
	created_by: default_created_by
)
static_pages_permission_home.translations.create(description: 'Permission to view the home page', locale: 'en')
static_pages_permission_home.translations.create(description: 'Berechtigung die Home-Seite zu betrachten', locale: 'de')

static_pages_permission_preferences = Permission.create(
	key: 'StaticPages.preferences',
	created_by: default_created_by
)
static_pages_permission_preferences.translations.create(description: 'Permission to view the preferences page', locale: 'en')
static_pages_permission_preferences.translations.create(description: 'Berechtigung die Einstellungsseite zu betrachten', locale: 'de')

static_pages_permission_contact = Permission.create(
	key: 'StaticPages.contact',
	created_by: default_created_by
)
static_pages_permission_contact.translations.create(description: 'Permission to view the contact page', locale: 'en')
static_pages_permission_contact.translations.create(description: 'Berechtigung die Kontaktseite zu betrachten', locale: 'de')

static_pages_permission_legal_notice = Permission.create(
	key: 'StaticPages.legal_notice',
	created_by: default_created_by
)
static_pages_permission_legal_notice.translations.create(description: 'Permission to view the legal notice page', locale: 'en')
static_pages_permission_legal_notice.translations.create(description: 'Berechtigung die Impressumsseite zu betrachten', locale: 'de')

static_pages_permission_help = Permission.create(
	key: 'StaticPages.help',
	created_by: default_created_by
)
static_pages_permission_help.translations.create(description: 'Permission to view the help page', locale: 'en')
static_pages_permission_help.translations.create(description: 'Berechtigung die Hilfeseite zu betrachten', locale: 'de')


# CATEGORIES
category_permission_index = Permission.create(
	key: 'Categories.index',
	created_by: default_created_by
)
category_permission_index.translations.create(description: 'Permission to list all categories.', locale: 'en')
category_permission_index.translations.create(description: 'Berechtigung alle Kategorien aufzulisten.', locale: 'de')

category_permission_show = Permission.create(
	key: 'Categories.show',
	created_by: default_created_by
)
category_permission_show.translations.create(description: 'Permission to view a category.', locale: 'en')
category_permission_show.translations.create(description: 'Berechtigung eine Kategorie anzuschauen.', locale: 'de')

category_permission_new = Permission.create(
	key: 'Categories.new',
	created_by: default_created_by
)
category_permission_new.translations.create(description: 'Permission to view the creation page of categories.', locale: 'en')
category_permission_new.translations.create(description: 'Berechtigung die Erstellungsseite von Kategorien anzuschauen.', locale: 'de')

category_permission_create = Permission.create(
	key: 'Categories.create',
	created_by: default_created_by
)
category_permission_create.translations.create(description: 'Permission to create a category.', locale: 'en')
category_permission_create.translations.create(description: 'Berechtigung eine Kategorie zu erstellen.', locale: 'de')

category_permission_edit = Permission.create(
	key: 'Categories.edit',
	created_by: default_created_by
)
category_permission_edit.translations.create(description: 'Permission to edit a category.', locale: 'en')
category_permission_edit.translations.create(description: 'Berechtigung eine Kategorie zu bearbeiten.', locale: 'de')

category_permission_update = Permission.create(
	key: 'Categories.update',
	created_by: default_created_by
)
category_permission_update.translations.create(description: 'Permission to update a category.', locale: 'en')
category_permission_update.translations.create(description: 'Berechtigung eine Kategorie zu aktualisieren.', locale: 'de')

category_permission_destroy = Permission.create(
	key: 'Categories.destroy',
	created_by: default_created_by
)
category_permission_destroy.translations.create(description: 'Permission to delete a category.', locale: 'en')
category_permission_destroy.translations.create(description: 'Berechtigung eine Kategorie zu löschen.', locale: 'de')


# DOCUMENTS
document_permission_index = Permission.create(
	key: 'Documents.index',
	created_by: default_created_by
)
document_permission_index.translations.create(description: 'Permission to list all documents.', locale: 'en')
document_permission_index.translations.create(description: 'Berechtigung alle Dokumente aufzulisten.', locale: 'de')

document_permission_show = Permission.create(
	key: 'Documents.show',
	created_by: default_created_by
)
document_permission_show.translations.create(description: 'Permission to view a document.', locale: 'en')
document_permission_show.translations.create(description: 'Berechtigung ein Dokument in der Detailansicht anzuschauen.', locale: 'de')

document_permission_new = Permission.create(
	key: 'Documents.new',
	created_by: default_created_by
)
document_permission_new.translations.create(description: 'Permission to view the document creation page.', locale: 'en')
document_permission_new.translations.create(description: 'Berechtigung die Dokumentenerstellungsseite anzuschauen.', locale: 'de')

document_permission_create = Permission.create(
	key: 'Documents.create',
	created_by: default_created_by
)
document_permission_create.translations.create(description: 'Permission to create a document.', locale: 'en')
document_permission_create.translations.create(description: 'Berechtigung ein Dokument zu erstellen.', locale: 'de')

document_permission_edit = Permission.create(
	key: 'Documents.edit',
	created_by: default_created_by
)
document_permission_edit.translations.create(description: 'Permission to edit a document.', locale: 'en')
document_permission_edit.translations.create(description: 'Berechtigung ein Dokument zu bearbeiten.', locale: 'de')

document_permission_update = Permission.create(
	key: 'Documents.update',
	created_by: default_created_by
)
document_permission_update.translations.create(description: 'Permission to update a document.', locale: 'en')
document_permission_update.translations.create(description: 'Berechtigung ein Dokument zu aktualisieren.', locale: 'de')

document_permission_destroy = Permission.create(
	key: 'Documents.destroy',
	created_by: default_created_by
)
document_permission_destroy.translations.create(description: 'Permission to delete a document.', locale: 'en')
document_permission_destroy.translations.create(description: 'Berechtigung ein Dokument zu löschen.', locale: 'de')

# COMMENTS
comment_permission_index = Permission.create(
	key: 'Comments.index',
	created_by: default_created_by
)
comment_permission_index.translations.create(description: 'Permission to list all comments.', locale: 'en')
comment_permission_index.translations.create(description: 'Berechtigung alle Kommentare aufzulisten.', locale: 'de')

comment_permission_show = Permission.create(
	key: 'Comments.show',
	created_by: default_created_by
)
comment_permission_show.translations.create(description: 'Permission to view a comment.', locale: 'en')
comment_permission_show.translations.create(description: 'Berechtigung ein Kommentar in der Detailansicht anzuschauen.', locale: 'de')

comment_permission_new = Permission.create(
	key: 'Comments.new',
	created_by: default_created_by
)
comment_permission_new.translations.create(description: 'Permission to view the comment creation page.', locale: 'en')
comment_permission_new.translations.create(description: 'Berechtigung die Kommentarerstellungsseite anzuschauen.', locale: 'de')

comment_permission_create = Permission.create(
	key: 'Comments.create',
	created_by: default_created_by
)
comment_permission_create.translations.create(description: 'Permission to create a comment.', locale: 'en')
comment_permission_create.translations.create(description: 'Berechtigung ein Kommentar zu erstellen.', locale: 'de')

comment_permission_edit = Permission.create(
	key: 'Comments.edit',
	created_by: default_created_by
)
comment_permission_edit.translations.create(description: 'Permission to edit a comment.', locale: 'en')
comment_permission_edit.translations.create(description: 'Berechtigung ein Kommentar zu bearbeiten.', locale: 'de')

comment_permission_update = Permission.create(
	key: 'Comments.update',
	created_by: default_created_by
)
comment_permission_update.translations.create(description: 'Permission to update a comment.', locale: 'en')
comment_permission_update.translations.create(description: 'Berechtigung ein Kommentar zu aktualisieren.', locale: 'de')

comment_permission_destroy = Permission.create(
	key: 'Comments.destroy',
	created_by: default_created_by
)
comment_permission_destroy.translations.create(description: 'Permission to delete a comment.', locale: 'en')
comment_permission_destroy.translations.create(description: 'Berechtigung ein Kommentar zu löschen.', locale: 'de')


# TAGS
tag_permission_index = Permission.create(
	key: 'Tags.index',
	created_by: default_created_by
)
tag_permission_index.translations.create(description: 'Permission to view all tags.', locale: 'en')
tag_permission_index.translations.create(description: 'Berechtigung alle Tags zu betrachten.', locale: 'de')


tag_permission_show = Permission.create(
	key: 'Tags.show',
	created_by: default_created_by
)
tag_permission_show.translations.create(description: 'Permission to view a tag.', locale: 'en')
tag_permission_show.translations.create(description: 'Berechtigung ein Tag in der Detailansicht anzuschauen.', locale: 'de')


# USERS
user_permission_index = Permission.create(
	key: 'Users.index',
	created_by: default_created_by
)
user_permission_index.translations.create(description: 'Permission to list all users.', locale: 'en')
user_permission_index.translations.create(description: 'Berechtigung alle Benutzer aufzulisten.', locale: 'de')

user_permission_show = Permission.create(
	key: 'Users.show',
	created_by: default_created_by
)
user_permission_show.translations.create(description: 'Permission to view a users\' profile page.', locale: 'en')
user_permission_show.translations.create(description: 'Berechtigung das Profil eines Benutzers anzuschauen.', locale: 'de')

user_permission_new = Permission.create(
	key: 'Users.new',
	created_by: default_created_by
)
user_permission_new.translations.create(description: 'Permission to view the registration page.', locale: 'en')
user_permission_new.translations.create(description: 'Berechtigung die Registrierungsseite anzuschauen.', locale: 'de')

user_permission_create = Permission.create(
	key: 'Users.create',
	created_by: default_created_by
)
user_permission_create.translations.create(description: 'Permission to create a user.', locale: 'en')
user_permission_create.translations.create(description: 'Berechtigung einen Benutzer zu erstellen.', locale: 'de')

user_permission_edit = Permission.create(
	key: 'Users.edit',
	created_by: default_created_by
)
user_permission_edit.translations.create(description: 'Permission to edit a user.', locale: 'en')
user_permission_edit.translations.create(description: 'Berechtigung einen Benutzer zu bearbeiten.', locale: 'de')

user_permission_update = Permission.create(
	key: 'Users.update',
	created_by: default_created_by
)
user_permission_update.translations.create(description: 'Permission to update a user.', locale: 'en')
user_permission_update.translations.create(description: 'Berechtigung einen Benutzer zu aktualisieren.', locale: 'de')

user_permission_destroy = Permission.create(
	key: 'Users.destroy',
	created_by: default_created_by
)
user_permission_destroy.translations.create(description: 'Permission to delete a user.', locale: 'en')
user_permission_destroy.translations.create(description: 'Berechtigung einen Benutzer zu löschen.', locale: 'de')


###############################################################################
# DEFAULT GROUP PERMISSIONS
###############################################################################

# Users
user_group_users.permissions << static_pages_permission_home
user_group_users.permissions << static_pages_permission_preferences
user_group_users.permissions << static_pages_permission_contact
user_group_users.permissions << static_pages_permission_legal_notice
user_group_users.permissions << static_pages_permission_help

user_group_users.permissions << category_permission_index
user_group_users.permissions << category_permission_show

user_group_users.permissions << document_permission_index
user_group_users.permissions << document_permission_show
user_group_users.permissions << document_permission_new
user_group_users.permissions << document_permission_create

user_group_users.permissions << comment_permission_index
user_group_users.permissions << comment_permission_show
user_group_users.permissions << comment_permission_new
user_group_users.permissions << comment_permission_create

user_group_users.permissions << tag_permission_index
user_group_users.permissions << tag_permission_show

user_group_users.permissions << user_permission_show

# Guests
user_group_guests.permissions << static_pages_permission_home
user_group_guests.permissions << static_pages_permission_contact
user_group_guests.permissions << static_pages_permission_legal_notice
user_group_guests.permissions << static_pages_permission_help

user_group_guests.permissions << category_permission_index
user_group_guests.permissions << category_permission_show

user_group_guests.permissions << document_permission_index
user_group_guests.permissions << document_permission_show

user_group_guests.permissions << comment_permission_index
user_group_guests.permissions << comment_permission_show

user_group_guests.permissions << tag_permission_index
user_group_guests.permissions << tag_permission_show

user_group_guests.permissions << user_permission_new
user_group_guests.permissions << user_permission_create


###############################################################################
# DEVELOPMENT ENVIRONMENT SETTINGS
###############################################################################

if Rails.env.development?
	user_mb = User.create(first_name: 'Michael', last_name: 'Barth', matriculation_number: 748890, 
		email: 'michael.barth@uni-ulm.de', password: '123456', password_confirmation: '123456', 
		user_group_id: user_group_admins.id, created_by: default_created_by)
	user_mb.translations.create(about: 'Krauts shrubbery doo', locale: 'en')
	user_mb.translations.create(about: 'Blub mäh narf', locale: 'de')

	user_1 = User.create_with_default_permissions(
		first_name: 'Hans', last_name: "Mueller", matriculation_number: 748890, 
		email: 'hans.mueller@uni-ulm.de', password: '123456', password_confirmation: '123456', 
		user_group_id: user_group_users.id, created_by: default_created_by)
	user_1.translations.create(about: "Hello, my name is #{user_1.name}!", locale: 'en')
	user_1.translations.create(about: "Hallo, mein Name lautet #{user_1.name}!", locale: 'de')
  
  user_mb = User.create(first_name: 'Sinan', last_name: 'Celik', matriculation_number: 748890, 
		email: 'sinan.celik@uni-ulm.de', password: '123456', password_confirmation: '123456', 
		user_group_id: user_group_admins.id, created_by: default_created_by)
	user_mb.translations.create(about: 'Krauts shrubbery doo', locale: 'en')
	user_mb.translations.create(about: 'Blub mäh narf', locale: 'de')
end